package com.zmxstudy.rbac.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zmxstudy.rbac.base.BaseController;
import com.zmxstudy.rbac.entity.Item;
import com.zmxstudy.rbac.service.ItemService;
import org.springframework.web.bind.annotation.*;

import java.nio.charset.StandardCharsets;
import java.sql.Wrapper;
import java.util.ArrayList;

/**
 * @Author:tianyu
 * @Date:2024-05-08 19:31
 */
@RestController
@RequestMapping("/item")
public class ItemController extends BaseController<ItemService, Item> {

    /**
     * 获取所有商品信息
     * @return  所有商品信息
     */
    @RequestMapping("/info")
    public ArrayList<Item> info() {
       return baseService.info();
    }

//    /**
//     * 获取商品的品牌信息分类
//     * @return 品牌信息分类
//     */
//    @RequestMapping("/info/category")
//    public ArrayList<String> infoCategory() {
//        return baseService.infoCategory();
//    }

    /**
     * 根据brand_id查询商品
     */

    @RequestMapping("/info/{brandId}")
    public ArrayList<Item> infoBrand(@PathVariable String brandId) {
        QueryWrapper<Item> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("brand_id", brandId);
        return (ArrayList<Item>) baseService.list(queryWrapper);
    }


    /**
     * 根据id查询商品
     */
    @RequestMapping("/info/get")
    public Item infoId(@RequestParam(value = "id", required = false) String id) {
        System.out.println(id);
        QueryWrapper<Item> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("id", id);
        Item item = baseService.getOne(queryWrapper);
        System.out.println(item);
        return item;
    }


}
